using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ARC_ApdetMap : EntityTypeConfiguration<ARC_Apdet>
    {
        public ARC_ApdetMap()
        {
            // Primary Key
            this.HasKey(t => new { t.INVNO, t.TRANSID, t.ITEM, t.PAYEE });

            // Properties
            this.Property(t => t.INVNO)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.TRANSID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.ITEM)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.PAYEE)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.OLDSTAFFID)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.TYPE)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(1);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.APDet_ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            // Table & Column Mappings
            this.ToTable("ARC_Apdet");
            this.Property(t => t.INVNO).HasColumnName("INVNO");
            this.Property(t => t.TRANSID).HasColumnName("TRANSID");
            this.Property(t => t.ITEM).HasColumnName("ITEM");
            this.Property(t => t.PAYEE).HasColumnName("PAYEE");
            this.Property(t => t.PERC).HasColumnName("PERC");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.AMOUNT).HasColumnName("AMOUNT");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.ADDED).HasColumnName("ADDED");
            this.Property(t => t.CHANGED).HasColumnName("CHANGED");
            this.Property(t => t.OLDAMOUNT).HasColumnName("OLDAMOUNT");
            this.Property(t => t.OLDSTAFFID).HasColumnName("OLDSTAFFID");
            this.Property(t => t.IDCHANGED).HasColumnName("IDCHANGED");
            this.Property(t => t.DUEG1ACCT).HasColumnName("DUEG1ACCT");
            this.Property(t => t.DUEG2ACCT).HasColumnName("DUEG2ACCT");
            this.Property(t => t.STAFFTYPE).HasColumnName("STAFFTYPE");
            this.Property(t => t.TYPE).HasColumnName("TYPE");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.APPROVED_DUEG1ACCT).HasColumnName("APPROVED_DUEG1ACCT");
            this.Property(t => t.APPROVED_DUEG2ACCT).HasColumnName("APPROVED_DUEG2ACCT");
            this.Property(t => t.APDet_ID).HasColumnName("APDet_ID");

            // Relationships
            this.HasOptional(t => t.currency1)
                .WithMany(t => t.ARC_Apdet)
                .HasForeignKey(d => d.CURRENCY);
            this.HasRequired(t => t.Item1)
                .WithMany(t => t.ARC_Apdet)
                .HasForeignKey(d => d.ITEM);
            this.HasRequired(t => t.ARC_Oe)
                .WithMany(t => t.ARC_Apdet)
                .HasForeignKey(d => new { d.TYPE, d.INVNO });
            this.HasRequired(t => t.ARC_Oe1)
                .WithMany(t => t.ARC_Apdet1)
                .HasForeignKey(d => new { d.TYPE, d.INVNO });
            this.HasRequired(t => t.ARC_Oedet)
                .WithMany(t => t.ARC_Apdet)
                .HasForeignKey(d => d.TRANSID);
            this.HasRequired(t => t.Vend)
                .WithMany(t => t.ARC_Apdet)
                .HasForeignKey(d => d.PAYEE);

        }
    }
}
